import Vue from 'vue'
import VueRouter from 'vue-router'
import Admin from '_views/Admin'
import Login from '_views/Login'
// 解决点击重定向的问题
const originalPush = VueRouter.prototype.push
// push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
    meta: {
      isNav: false
    }
  },
  {
    path: '/login',
    name: '登录',
    meta: {
      isNav: false
    },
    component: Login
  },
  {
    path: '/admin',
    name: '管理员',
    redirect: '/admin/dashboard',
    meta: {
      isNav: false
    },
    component: Admin,
    children: [
      {
        path: '/admin/dashboard',
        name: '仪表盘',
        icon: 'el-icon-s-help',
        meta: {
          isNav: true
        },
        component: () => import('_views/DashBoard')
      },
      {
        path: '/admin/itemlist',
        name: '商品列表',
        icon: 'el-icon-menu',
        meta: {
          isNav: true
        },
        component: () => import('_views/ItemList')
      },
      {
        path: '/admin/additem',
        name: '增加商品',
        icon: 'el-icon-edit-outline',
        meta: {
          isNav: true
        },
        component: () => import('_views/ItemAdd')
      },
      {
        path: '/admin/itemupadte',
        name: '修改商品信息',
        meta: {
          isNav: false
        },
        component: () => import('_views/ItemUpdate')
      },
      {
        path: '/admin/messagelist',
        name: '消息中心',
        icon: 'el-icon-message',
        meta: {
          isNav: true
        },
        component: () => import('_views/MessageList')
      },
      {
        path: '/admin/setting',
        name: '设置',
        icon: 'el-icon-setting',
        meta: {
          isNav: true
        },
        component: () => import('_views/Setting')
      }
    ]
  },
  {
    path: '*',
    name: '404',
    meta: {
      isNav: false
    },
    component: () => import('_views/NotFound')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export {
  routes,
  router
}
